# 记录用户日志并查看
import sys
import time

log_file = "login_log.txt"


def mylog_writer(msg):
    with open(log_file, "a") as file:
        file.write(msg)
        file.write('\n')


def mylog_read():
    with open(log_file, "r") as file:
        for readline in file.readlines():
            print(readline)


while True:
    username = input("请输入用户名：")
    password = input("请输入密码：")
    if "yujikuan" == username and "vcom123" == password:
        mylog_writer(f"登陆成功, 用户：{username},登陆时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}")
        print("登陆成功")
        while True:
            s1 = eval(input("输入提示 0 是退出，1 查看登陆日志"))
            if s1 == 0:
                sys.exit()
            elif s1 == 1:
                mylog_read()
    else:
        print("用户名或密码不正确，登陆失败")
        mylog_writer(
            f"用户名或密码不正确，登陆失败,用户：{username},时间：{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}")
